package com.briup.mt.service.impl;

import com.briup.mt.bean.Article;
import com.briup.mt.bean.ArticleExample;
import com.briup.mt.bean.Category;
import com.briup.mt.bean.CategoryExample;
import com.briup.mt.dao.ArticleMapper;
import com.briup.mt.service.IArticleService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;


import javax.annotation.Resource;
import java.util.List;

@Service
public class ArticleServiceImpl implements IArticleService {
    @Resource
    private ArticleMapper articleMapper;
    @Override
    public List<Article> query(String title) {
        ArticleExample example = new ArticleExample();
        if (!StringUtils.isEmpty(title)) {
            example.createCriteria().andTitleLike("%" + title + "%");
        }
        List<Article> list = articleMapper.selectByExample(example);

        return articleMapper.selectByExample(example);
    }
    @Override
    public void saveOrUpdate(Article article) {
        if (article.getId()==null){
            articleMapper.insert(article);
        }
        else{
            articleMapper.updateByPrimaryKey(article);
        }
    }
    @Override
    public void deleteById(long id) {
        articleMapper.deleteByPrimaryKey(id);
    }
}
